package com.nuo.hibernate;

import java.util.ArrayList;
import java.util.List;


import org.hibernate.Session;
import org.hibernate.Transaction;

import com.nuo.hibernate.entity.User;

public class UserManage {
	
	public List getAllUser(){
		List list = new ArrayList();
		Session session = HibernateSessionFactory.getSession();
		Transaction ts = session.beginTransaction();
		
		try{
			list = session.createCriteria(User.class).list();;
		}catch(Exception e){
			ts.rollback();
		}finally{
			session.close();
		}
		
		return list;
	}
	
	public void saveOrUpdate(User user){
		Session session = HibernateSessionFactory.getSession();
		Transaction ts = session.beginTransaction();
		
		try{
			session.saveOrUpdate(user);
		}catch(Exception e){
			ts.rollback();
		}finally{
			session.close();
		}
	}
}
